<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class Node extends Model {

	protected $guarded = [];

    public static function mkMenu() {
		$rules = Role::where('id',session('user_info')['role_id'])->value('rules');
		if($rules == '*'){
			$where = [];
		}else{
			$rules = explode(',',$rules);
			$where = function($query)use($rules){
				foreach($rules as $v){
					$query->orWhere("id",$v);
				}
			};
		}
		$Menu = Node::where('is_menu',"是")->where($where)->orderBy('sort','asc')->get()->toArray();
		return \App\Http\Controllers\Admin\Common::getTree($Menu,false);
	}
}
